package com.jieao.content.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jieao.common.core.domain.AjaxResult;
import com.jieao.content.domain.ArticleCommentLike;
import com.jieao.content.mapper.ArticleCommentLikeMapper;
import com.jieao.content.service.IArticleCommentLikeService;
import com.jieao.framework.util.ShiroUtils;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @Description
 * @Author weifanl
 * @Date2020/5/21 15:33
 **/
@Service
public class ArticleCommentLikeServiceImpl extends ServiceImpl<ArticleCommentLikeMapper , ArticleCommentLike> implements IArticleCommentLikeService {
    @Override
    public AjaxResult insertCommentLike(ArticleCommentLike commentLike) {
        ArticleCommentLike like = baseMapper.selectOne(Wrappers.<ArticleCommentLike>query().lambda()
                .eq(ArticleCommentLike::getCommentId,commentLike.getCommentId())
                .eq(ArticleCommentLike::getUserId,ShiroUtils.getUserId())
        );
        if(null == like){
            commentLike.setUserId(ShiroUtils.getUserId());
            commentLike.setCreateTime(new Date());
            baseMapper.insert(commentLike);
            return AjaxResult.success("点赞成功");
        }else{
            return AjaxResult.warn("重复点赞");
        }
    }

}
